@if "%1"=="clean" goto CLEAN
@if "%1"=="test" goto TEST
@if "%1"=="test2" goto TEST2
@if "%1"=="perftest" goto PERFTEST
@if "%1"=="perftest-plain" goto PERFTEST-PLAIN
@if "%1"=="stefan" goto STEFAN
@if "%1"=="stress" goto STRESS

@if not "%LUA51%"=="" goto LUADIR_OK
@if exist "C:\Program Files\Lua5.1\lua5.1.exe" set LUA51=C:\Progra~1\Lua5.1
@if "%LUA51%"=="" goto ERR_NOLUA
:LUADIR_OK

@if exist gluax.? if exist ..\gluax\gluax.? del gluax.?
@if not exist gluax.? copy ..\gluax\gluax.? .
@if not exist assert.lua copy ..\Core\assert.lua .
@if not exist strict.lua copy ..\Core\strict.lua .

@if not "%VCINSTALLDIR%"=="" goto VC

@REM
@REM Win32 (MinGW) build commands
@REM
gcc -Wall -O2 -I "%LUA51%\include" -L "%LUA51%" -llua5.1 -shared -o lua51-lanes.dll -DGLUA_LUA51 gluax.c lanes.c
@goto EXIT

:VC
@REM
@REM Win32 (Visual C++ 2005 Express) build commands
@REM
@REM MS itself has warnings in stdlib.h (4255), winbase.h (4668), several (4820, 4826)
@REM
cl /Wall /wd4255 /wd4668 /wd4820 /wd4826 /O2 /I "%LUA51%\include" /DGLUA_LUA51 /LDd /Felua51-lanes.dll gluax.c lanes.c "%LUA51%\lua5.1.lib"
@goto EXIT

:CLEAN
if exist *.dll del *.dll
@goto EXIT

:TEST
@REM "make test" does not automatically build/update the dll. We're NOT a makefile. :!
@REM
"%LUA51%\lua5.1" -lstrict test.lua
@goto EXIT

:TEST2
"%LUA51%\lua5.1" -lstrict test2.lua
@goto EXIT

REM 'timeit' does not handle executables in space-containing path. So WHY
REM does MS need to make all their default paths HAVE spaces? :) :) :)
REM (even if using quotes - I tried...)
:PERFTEST
timeit %LUA51%\lua5.1 -lstrict perftest.lua %2 %3 %4
@goto EXIT

:PERFTEST-PLAIN
timeit %LUA51%\lua5.1 -lstrict perftest.lua --plain %2 %3 %4
@goto EXIT

:STEFAN
"%LUA51%\lua5.1" -lstrict stefan.lua
@goto EXIT

:STRESS
"%LUA51%\lua5.1" -lstrict test.lua
"%LUA51%\lua5.1" -lstrict perftest.lua 100
"%LUA51%\lua5.1" -lstrict perftest.lua 50 -prio=-1,0
"%LUA51%\lua5.1" -lstrict perftest.lua 50 -prio=0,-1
"%LUA51%\lua5.1" -lstrict perftest.lua 50 -prio=0,2
"%LUA51%\lua5.1" -lstrict perftest.lua 50 -prio=2,0
"%LUA51%\lua5.1" -lstrict stefan.lua
"%LUA51%\lua5.1" -lstrict stefan.lua
"%LUA51%\lua5.1" -lstrict stefan.lua

@echo All seems okay!
@goto EXIT

REM ---
:ERR_NOLUA
@echo ***
@echo *** Please set LUA51 to point to LuaBinaries directory:
@echo ***
@echo *** http://luabinaries.luaforge.net/download.html
@echo ***	lua5_1_2_Win32_dll8_lib
@echo ***	lua5_1_2_Win32_bin
@echo ***
@echo *** Extracting to C:\Program Files\Lua5.1 will be autodetected.
@echo.
@goto EXIT

:EXIT
